﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class WorkTimeN_WorkTime_AddUpLog : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;
            master.HelpHref = "";
            master.PageName = "考勤汇总错误日志";
            master.PicUrl = "";
            master.IntiBar();


            InitializeComponent();

            Master.DataSource = WMaster;
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTimeN_WorkTime_AddUpLog));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SWorkTime.ViewWorkTime_AddUpLog";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void wgvMaster_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView drv = (DataRowView)e.Row.DataItem;

            LinkButton lbMT = e.Row.FindControl("MTAddUp") as LinkButton;
            LinkButton lbFF = e.Row.FindControl("FlowForm") as LinkButton;

            LinkButton UpResult = e.Row.FindControl("UpResult") as LinkButton;


            CheckBox ckResult = e.Row.FindControl("MTAddUpResult") as CheckBox;

            ckResult.Enabled = false;
            string url = "";
            string id = drv["Ltid"].ToString().Substring(drv["Ltid"].ToString().IndexOf("=") + 1
                , drv["Ltid"].ToString().Length - drv["Ltid"].ToString().IndexOf("=") - 1);

            switch (drv["Ltable"].ToString())
            {
                case "WorkTime_Leave":
                    url = "WorkTimeLeave.aspx?sid=";
                    break;
                case "WorkTime_Overtime":
                    url = "WorkTimeOvertime.aspx?id=";
                    break;
                case "WorkTime_Out":
                    url = "WorkTimeOut.aspx?id=";
                    break;
                case "WorkTime_Evection":
                    url = "WorkTimeEvection.aspx?id=";
                    break;
                case "WT_MendWorkOn":
                    url = "MendWorkOn.aspx?id=";
                    break;
            }

            lbFF.Attributes.Add("onclick", "openPG('" + url + id + "');return false");


            if (Convert.ToBoolean(drv["LogResult"]))
            {

                UpResult.Visible = false;

                lbMT.Enabled = false;
                ckResult.Checked = true;
            }
            else
            {
                UpResult.Visible = true;
                
                lbMT.Enabled = true;
                ckResult.Checked = false;

                lbMT.Attributes.Add("onclick", "return confirm('确认手动处理 表" + drv["Ltable"].ToString() + " " + drv["Ltid"].ToString() + "？')");
                lbMT.CommandArgument = drv["Ltable"].ToString() + "," + drv["Ltid"].ToString() + "," + drv["Lid"].ToString();
                lbMT.CommandName = "MT";


                UpResult.CommandName = "UpRS";
                UpResult.CommandArgument = drv["Lid"].ToString();
                UpResult.Attributes.Add("onclick", "return confirm('确认手动更新处理状态 表" + drv["Ltable"].ToString() + " " + drv["Ltid"].ToString() + "？')");

            }
        }
    }

    protected void wgvMaster_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "MT")
        {
            lbMsg.Text = "";

            try
            {
                string[] m = e.CommandArgument.ToString().Split(',');

                if (m.Length == 3)
                {
                    object[] objParam = new object[] { m[0], m[1], m[2] };

                    object[] myRet = Srvtools.CliUtils.CallMethod("SWorkTime", "ToAddUpMT", objParam);
                    if (Convert.ToBoolean(myRet[1]))
                    {
                        ClientScript.RegisterStartupScript(GetType(), "", "alert('处理成功!');location.href='WorkTime_AddUpLog.aspx'", true);
                    }
                }
            }
            catch (Exception ex)
            {
                lbMsg.Text = ex.Message;
            }
        }
        else if(e.CommandName == "UpRS" && e.CommandArgument.ToString() != "")
        {
            Srvtools.CliUtils.ExecuteSql("GLModule", "cmdRefValUse",
                "update WorkTime_AddUpLog set LogResult=1 where Lid=" + e.CommandArgument.ToString(), true, Srvtools.CliUtils.fCurrentProject);
            ClientScript.RegisterStartupScript(GetType(), "", "alert('处理成功!');location.href='WorkTime_AddUpLog.aspx'", true);
           // Srvtools.CliUtils.ExecuteSql(
        }
    }

    protected void Slog_Click(object sender, EventArgs e)
    {
        string tb = txtLtableS.Text.Trim() != "" ? " AND Ltable like '%" + txtLtableS.Text.Trim() + "%' " :"";
        string tid = txtLtidS.Text.Trim() != "" ? " AND Ltid like '%" + txtLtidS.Text.Trim() + "%' " : "";
        string trs = ddpResultS.SelectedValue != "-1" ? " AND LogResult=" + ddpResultS.SelectedValue :"";

        InitializeComponent();

        WMaster.SetWhere(" 1=1 " + tb + tid + trs);
        Master.DataSource = WMaster;
    }
}
